CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/[owner]/[project].tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
// Page for a project that is owned by a named account
7
// or organization.
8
9
import getProjectId from "lib/names/project";
10
import withCustomize from "lib/with-customize";
11
import getProjectInfo from "lib/project/info";
12
import getProject from "lib/share/get-project";
13
import Project from "components/project/project";
14
import Organization from "components/share/proxy/organization";
15
import getPublicPathInfoGithub from "lib/share/proxy/get-public-path-info-github";
16
17
export default function Page(props) {
18
if (props.project_id) {
19
return <Project {...props} />;
20
} else {
21
// e.g., for listing all github repos in an org:
22
return <Organization {...props} />;
23
}
24
}
25
26
export async function getServerSideProps(context) {
27
const { owner, project } = context.params;
28
29
try {
30
let props;
31
if (owner == "github") {
32
// special case for special github URL's
33
// This is a URL like https://cocalc.com/github/cocalc,
34
// which will end up listing all public repos under the cocalc org (say).
35
props = {
36
...(await getPublicPathInfoGithub(`${owner}/${project}`)),
37
organization: project,
38
};
39
} else {
40
const project_id = await getProjectId(owner, project);
41
props = {
42
project_id,
43
...(await getProjectInfo(project_id, context.req)),
44
...(await getProject(project_id, [
45
"name",
46
"title",
47
"description",
48
"avatar_image_full",
49
])),
50
};
51
}
52
return await withCustomize({ context, props });
53
} catch (err) {
54
console.log(err);
55
return { notFound: true };
56
}
57
}
58
59